﻿using System;
using System.Windows.Forms;

namespace Compiler.LabForms
{
    public partial class UserForm : Form
    {
        public UserForm()
        {
            InitializeComponent();
        }

        private void UserForm_Load(object sender, EventArgs e)
        {
            groupBox.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(surnameBox.Text) || string.IsNullOrEmpty(nameBox.Text))
            {
                MessageBox.Show(@"Фамилия и имя обязательны для ввода", @"Сообщение",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
            }
            else
            {
                Lab.CreateNewLab();
                MainForm.GetMainForm().Text = @"Компилятор C mini - *Новая несохраненная работа*";
                MainForm.GetMainForm().EnableMenuLinks();
                MainForm.GetMainForm().QuickStartMessages();
                Lab.GetLab().Surname = surnameBox.Text;
                Lab.GetLab().Name = nameBox.Text;
                Lab.GetLab().Group = groupBox.SelectedItem.ToString();
                Close();
            }
        }

        private bool _altF4Pressed;

        private void UserForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!_altF4Pressed) return;
            if (e.CloseReason == CloseReason.UserClosing) 
            {
                e.Cancel = true;
            }
            _altF4Pressed = false;
        }

        private void UserForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Alt && e.KeyCode == Keys.F4) 
            {
                _altF4Pressed = true;
            }
        }
    }
}
